//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
class LoadingUI extends egret.Sprite {

    public constructor() {
        super();
        this.createView();
    }

    private textField:egret.TextField;
    private bmp:egret.Bitmap;
    private sp:egret.Sprite;
    private sp2:egret.Sprite;
     private createView():void {
        

       this.bmp=new egret.Bitmap();
       this.bmp.texture=RES.getRes('logo_png');
       this.bmp.anchorOffsetX=this.bmp.width/2;
       this.bmp.anchorOffsetY=this.bmp.height/2;
       this.bmp.x=740/2;
       this.bmp.y=1136*0.4;
       this.addChild(this.bmp);

       this.bmp.y=1136*0.4+300;
       this.bmp.alpha=0;
       egret.Tween.get(this.bmp).to({alpha:1,y:1136*0.4},1000,egret.Ease.backOut);

        this.sp=new egret.Sprite();
        this.sp.graphics.beginFill(0xFFFFFF,1);
        this.sp.graphics.drawRect(0,0,350,4);
        this.sp.anchorOffsetY=this.sp.height/2;
        this.sp.x=(740-this.sp.width)/2;
        this.sp.y=1136/2+0;
        this.sp.alpha=0;
        egret.Tween.get(this.sp).to({alpha:1},700,egret.Ease.cubicIn);

        this.sp2=new egret.Sprite();
        this.sp2.graphics.beginFill(0xff6600,1);
        this.sp2.graphics.drawRect(0,0,350,4);
        this.sp2.anchorOffsetX=0;
        this.sp2.anchorOffsetY=this.sp2.height/2;
        this.sp2.x=(740-this.sp2.width)/2;
        this.sp2.y=1136/2+0;
        this.sp2.scaleX=0;
        this.sp2.alpha=0;
        egret.Tween.get(this.sp2).to({alpha:1},700,egret.Ease.cubicIn);

        this.addChild(this.sp);
        this.addChild(this.sp2);

    }
    private touchHandler(e:egret.TouchEvent):void
    {
        
    }

    
    public setProgress(current:number, total:number):void {
        // console.log(current,total);
        this.sp2.scaleX=current/total;
        var myThis=this;
        if(current/total==1)
        {            
            // this.parent.removeChild(this);
            egret.Tween.removeTweens(this.bmp);
            egret.Tween.removeTweens(this.sp);
            egret.Tween.removeTweens(this.sp2);

            egret.Tween.get(this.bmp).to({alpha:0,y:1136*0.4-300},1000,egret.Ease.cubicInOut);
            egret.Tween.get(this.sp).to({alpha:0,y:1136/2+633},1000,egret.Ease.cubicInOut);
            egret.Tween.get(this.sp2).to({alpha:0,y:1136/2+633},1000,egret.Ease.cubicInOut);

          
            setTimeout(function():void
            {               
                myThis.parent['LoadComplete']();
            },1000);
        }
    }
  
}
